//index.js
const EventEmitter = require('../../common/EventEmitter');
const User = require('../../common/User');
const config = require('../../config/config');
const backgroudColor = require('../../config/backgroundColor');
const requester = require('../../common/Requester');
const util = require('../../common/util');

Page({
    data: {
        deviceInfo: {
            windowHeight: ''
        },
        userInfo: {},
        imageList: '',
        isRefreshing: false
    },

    onLoad: function (param) {
        let me = this;
        // Get system info and store to appGlobalData.
        util.getSystemInfo();

        // 初始化用户登录数据等,初始化完毕则请求数据，否则弹出失败页面。
        User.checkSession((res) => {
            this.initData();
        });

        EventEmitter.addListener('backThisPage', (bParam) => {

        });

        EventEmitter.addListener('backFormSend', (bParam) => {
        });
    },

    onShow: function (param) {

    },

    onPullDownRefresh: function () {
        this.setData({
            isRefreshing: true
        });
    },

    onPullDownStop: function () {
        wx.stopPullDownRefresh();
        this.setData({
            isRefreshing: false
        });
    },

    onReachBottom: function () {
        this.getData(true);
    },

    initData: function () {

    },

    /**
     * 获取数据。
     * @param isLoadMore boolean 是否是加载更多。
     */
    getData: function (isLoadMore) {

    },

    updateData: function () {

    },

    /**
     * 获取资源列表
     * @param categoryName String
     * @param successCb Function
     */
    getResourceList: function (pageIndex) {
        let me = this;
        requester.request({
            url: requester.service.resourceList,
            data: {},
            success: function (res) {

            }
        });
    },

    addImage: function (e) {
        let me = this;
        wx.chooseImage({
            sizeType: ['original', 'compressed'],
            sourceType: ['album'],
            success: (res) => {
               /* wx.navigateTo({
                    url: '../send/send?url=' + tempFilePath
                    + "&category=" + curCateName + "&from=main"
                });*/
            }
        });
    },

    onShareAppMessage: function (res) {

    },
    setRandomBack: function () {
        let colors = backgroudColor.colors,
            len = colors.length,
            random = Math.floor(Math.random() * len);
        return colors[random];
    }
});
